<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:xi="http://www.w3.org/2001/XInclude"
      xmlns:py="http://genshi.edgewall.org/">
<!-- ! Render the ticket field form based on ticket items defined in trac system -->

<!--! List existing tickets -->

<head>
	<script>

	$("input[name='ajax_button']").click(function() {  
		/*
		 * Get the id of the form containing the button clicked
		 */
		formName = $(this).parents('form:first').attr("id");
		/*
		 * Get the serialized content of this form 
		 */
		formData = $('#'+formName).serialize()
		
		// Debug message
		//alert("Clicked Button FormName[ " +formName+ " ]\nData - " + formData);
		/*
		 * Steps to complete defect recording
		 * 1.) Submit data via ajax
		 * 1.1) Get result back and add to list of tickets open against this step 
		 * 2.) Disable radio button selections 
		 * 3.) Ask if the user would like to continue testing. 
		 * 
		 */
		$.ajax({
			type: "POST",
				url: "ajax",
				data: formData,
				cache: false,
				success: function(html){
					
					//result = jQuery.parsejson(json);
					alert("Ticket Created " + html);
				}
		});
	});
	

	</script>
	
</head>


<div>
<div id="ticketList" >
	<fieldset>
		<legend>Open Tickets</legend>
		<div id="tabs">
			<ul>
				<li py:for="open in opened">
					<a href="" ></a>
					<!-- 
					Note: Add feature to send comment variable to existing ticket. 
					This will populate the ticket commnet section with details referencing the 
					current test run. 
					
					Example
					Tester determines that a defect is found in step 5. 
					Several defects have already been registered. If the defect is similar 
					to an existing ticket, automatically populate the comment section with some
					information about the current testing experience. 
					"/ticket/1?comment=this+is+a+test+comment" 
					
					-->
				</li>
				<li>
					<a href="${href.report()}" target="_blank" >See All</a>
					
				</li>
			</ul>
		</div>
	</fieldset>	
</div>
<!--! Create new case  -->
<div id="ticketNew" >
	<form id="testticket_${step}" method="post" py:with="revoke_perm = 'PERMISSION_REVOKE' in perm" action="">
	<fieldset>
	   	<legend>Create ticket for Step [${step}] :</legend>
		<input type="hidden" name="reg_id" value="${reg}" />
		<input type="hidden" name="step_id" value="${step}" />
		<input type="hidden" name="ajax_request" value="Create Ticket" />
		
		
		<div >
			<div py:for="item in ticket" id="ticket_field" >
								
				<div py:choose="item.display">
					<span py:when="'yes'">
						<div py:choose="item.type">
							<span py:when="'text'">
								<label for="${item.name}">${item.label}:</label><input type="text" id="${item.name}" name="${item.name}"   />
							</span>
							<span py:when="'textarea'">
								<fieldset>
								<legend>${item.label}:</legend>
								<textarea id="desc_wiki_${step}" cols="85" rows="10" name="${item.name}" class="wikitext trac-resizable"  ></textarea>
								</fieldset>
							</span>
							<span py:when="'radio'">
								<fieldset>
									<legend>${item.label}</legend>
									<py:for each="option in item.options">
										<label for="option">${option}:</label><input type="radio" id="option" name="${item.name}" value="option" />
									</py:for>
								</fieldset>
							</span>
							<span py:when="'select'">
								
								<label for="${item.name}">${item.label}:</label> <select id="${item.name}" name="${item.name}" >
									<py:for each="option in item.options">
										<option value="option">${option}</option>
									</py:for>
								</select>
							</span>
						</div>
					</span>
					<!-- !
					<span py:when="'description'">
						<fieldset>
						<legend>${item.label}:</legend>
						<textarea id="desc_wiki_${step}" cols="85" rows="10" name="item.name" class="wikitext trac-resizable"  ></textarea>
						</fieldset>
					</span>
					-->
					
					<span py:otherwise="">
						<py:choose>
							<py:when test="item.value">
								<!-- Capture those values that have default settings -->
								<input type="hidden" name="${item.name}" value="${item.value}" />
							</py:when>
							<py:otherwise>
								<!-- Updated: 08/05/2011: Change default ticke create behavior to leave fields blank if no input value is given
										This will replace the current action of adding the values 'UNDEFINED' -->
								<input type="hidden" name="${item.name}" value="" />
							</py:otherwise>
						</py:choose>	
					</span> 
					
					
				</div>
			</div>
			<div>
				<input type="button" name="ajax_button" value="${_('Create Ticket')}" />
			</div>
		</div>
	</fieldset>
	</form>
</div>


<!--! Save  
<div id="ticketNew" >
	<form id="testticket_${step}" method="post" py:with="revoke_perm = 'PERMISSION_REVOKE' in perm" action="">
	<fieldset>
	   	<legend>Create ticket for Step [${step}] :</legend>
		<input type="hidden" name="plan_id" value="${plan}" />
		<input type="hidden" name="reg_id" value="${reg}" />
		<input type="hidden" name="step_id" value="${step}" />
		<div >
			<div py:for="item in ticket" id="ticket_field" >
				<div py:choose="item.type">
					<span py:when="'text'">
						<label for="item.name">${item.label}:</label><input type="text" id="item.name" name="item.name"   />
					</span>
					<span py:when="'textarea'">
						<fieldset>
						<legend>${item.label}:</legend>
						<textarea id="item.name" cols="85" rows="10" class="wikitext trac-resizable" name="item.name" ></textarea>
						</fieldset>
					</span>
					<span py:when="'radio'">
						<fieldset>
							<legend>${item.label}</legend>
							<py:for each="option in item.options">
								<label for="option">${option}:</label><input type="radio" id="option" name="item.name" value="option" />
							</py:for>
						</fieldset>
					</span>
					<span py:when="'select'">
						
						<label for="item.name">${item.label}:</label> <select id="item.name" name="item.name" >
							<py:for each="option in item.options">
								<option value="option">${option}</option>
							</py:for>
						</select>
					</span>
				</div>
			</div>
		</div>
	</fieldset>
	</form>
</div>
-->
</div>
</html>

<!-- !
Example fields
2011-04-21 11:59:57,612 Trac[web_ui] DEBUG:  
[
{'type': 'text', 'name': 'summary', 'label': 'Summary'}, 
{'type': 'text', 'name': 'reporter', 'label': 'Reporter'}, 
{'type': 'text', 'name': 'owner', 'label': 'Owner'}, 
{'type': 'textarea', 'name': 'description', 'label': 'Description'}, 
{'label': 'Type', 'type': 'select', 'options': [u'defect', u'enhancement', u'task'], 'value': u'defect', 'name': 'type'}, 
{'name': 'status', 'type': 'radio', 'value': '', 'label': 'Status', 'optional': True, 'options': [u'accepted', u'assigned', u'closed', u'new', u'reopened']}, 
{'label': 'Priority', 'type': 'select', 'options': [u'blocker', u'critical', u'major', u'minor', u'trivial'], 'value': u'major', 'name': 'priority'}, 
{'name': 'milestone', 'type': 'select', 'value': u'Project-C', 'label': 'Milestone', 'optional': True, 'options': [u'TESTING', u'Project-A', u"Liz's Project", u'Project-B', u'Project-C', u'Project-D']}, 
{'label': 'Component', 'type': 'select', 'options': [u'Foo', u'component1', u'component2'], 'value': u'', 'name': 'component'}, 
{'name': 'version', 'type': 'select', 'value': u'', 'label': 'Version', 'optional': True, 'options': [u'2.0', u'1.0']}, 
{'name': 'resolution', 'type': 'radio', 'value': u'fixed', 'label': 'Resolution', 'optional': True, 'options': [u'fixed', u'invalid', u'wontfix', u'duplicate', u'worksforme']}, 
{'type': 'text', 'name': 'keywords', 'label': 'Keywords'}, 
{'type': 'text', 'name': 'cc', 'label': 'Cc'}, 
{'type': 'time', 'name': 'time', 'label': 'Created'}, 
{'type': 'time', 'name': 'changetime', 'label': 'Modified'}, 
{'name': u'test_five', 'value': u'dos', 'label': u'Radio buttons are fun', 'options': [u'uno', u'dos', u'tres', u'cuatro', u'cinco'], 'custom': True, 'type': u'radio', 'order': 0}, 
{'name': u'test_four', 'value': u'two', 'label': u'My selectbox', 'options': [u'one', u'two', u'third option', u'four'], 'custom': True, 'type': u'select', 'order': 0}, 
{'name': u'test_one', 'format': 'plain', 'value': '', 'custom': True, 'label': u'Just a text box', 'type': u'text', 'order': 0}, 
{'name': u'test_six', 'format': 'plain', 'label': u'This is a large textarea', 'value': u'Default text', 'height': 30, 'width': 60, 'custom': True, 'type': u'textarea', 'order': 0}, 
{'name': u'test_three', 'value': u'1', 'label': u'Some checkbox', 'custom': True, 'type': u'checkbox', 'order': 0}, 
{'name': u'test_two', 'format': u'wiki', 'value': u'Default [mailto:joe@nospam.com owner]', 'custom': True, 'label': u'Another text-box', 'type': u'text', 'order': 0}
]
-->

